package querysrc;

import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import com.subway.babynote.syncdata.*;


public class query_gettip extends query {
	public query_gettip(sqlConnectionHandler sqlconhandler)
	{
		super(sqlconhandler);
	}	
	
	public List<ClientDataRecordBase> get_tip()
	{
		querydb qdb = null;
		ResultSet rs = null;
		Connection con = null;
		ArrayList<ClientDataRecordBase> tips = new ArrayList<ClientDataRecordBase>();
		try
		{			
			int hour = this.get_day_am_pm();
			boolean bret = true;
			con = this.init();	
			qdb = new querydb(con,sqlscripts.sql_get_tip_today);		
			bret = qdb.prePS();		
			if(bret)
			{
				qdb.ps.setInt(1, hour);
				rs = qdb.execPSQuery();
				if(rs.next())
				{
					rs.beforeFirst();
					while(rs.next())
					{
						String content = rs.getString(sqlscripts.sql_get_tip_today_c1_c);					
						Date s_date =StringUtil.str2dateonly(rs.getString(sqlscripts.sql_get_tip_today_c2_uid));
						if(hour==2)
							s_date = StringUtil.addhour(s_date, 12);
						tips.add(new ClientDataRecord.tipRecord(content,s_date));						
					}					
				}
			}			
			return tips;
		}
		catch(SQLException se) {
		      System.out.println("SQLException: "+se.getMessage());
		      return tips;
	    }
		catch(Exception e)
		{
			e.printStackTrace();
			return tips;
		}
		finally
		{
			this.release_resultset(rs);
			this.release_querydb(qdb);
			this.release_connection(con);
			this.finalize();
		}
	}
}
